package com.songlanyun.modules.aboutus.controller.admin;

import com.songlanyun.common.annotation.RepeatSubmit;
import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.aboutus.entity.AboutUsEntity;
import com.songlanyun.modules.aboutus.service.AboutUsService;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 关于我们
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2021-03-30 15:54:03
 */
@RestController
@RequestMapping("admin/about/us")
public class AboutUsAdminController extends AbstractController {
    @Autowired
    private AboutUsService aboutUsService;


    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("aboutus:aboutus:info")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = aboutUsService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 详情
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("aboutus:aboutus:info")
    public R info(@PathVariable("id") Long id) {
        AboutUsEntity aboutUsEntity = aboutUsService.getById(id);

        return R.ok().put("data", aboutUsEntity);
    }

    /**
     * 保存
     */
    @RepeatSubmit("1")
    @PostMapping("/save")
    @SysLog("保存关于我们")
    //@RequiresPermissions("aboutus:aboutus:save")
    public R save(@RequestBody AboutUsEntity aboutUs) {
        ValidatorUtils.validateEntity(aboutUs);
        verifyAdmin();
        aboutUsService.save(aboutUs);

        return R.ok();
    }

    /**
     * 修改关于我们
     */
    @RepeatSubmit("1")
    @PutMapping("/update")
    @SysLog("修改关于我们")
    //@RequiresPermissions("aboutus:aboutus:save")
    public R update(@RequestBody AboutUsEntity aboutUs) {
        ValidatorUtils.validateEntity(aboutUs);
        verifyAdmin();
        aboutUsService.updateById(aboutUs);

        return R.ok();
    }

    /**
     * 删除
     */
    @RepeatSubmit("1")
    @DeleteMapping("/delete/{id}")
    @SysLog("删除关于我们")
    //@RequiresPermissions("aboutus:aboutus:save")
    public R delete(@PathVariable("id") Long id) {
        verifyAdmin();
        aboutUsService.removeById(id);

        return R.ok();
    }


}
